import { defineStore } from 'pinia';
// @ts-ignore
import { reactive, ref } from 'vue';
import { getSystemConf } from "@/api/cms";
export const useSystemStore  = defineStore('system', () => {

    const state = reactive({
        customer: '', //客服电话
        miniAppLogo: '', // logo
        miniAppName: '', // 名称
        shareCover: '', //分享
        shareTitle: '',
        mallPickupAddress: '',
        mallPickupAddressName: '',
        mallPickupAddressMobile: '',
        mallPickupAddressLatitude: '',
        mallPickupAddressLongitude: '',
        mallName: '',
        mallCustomerMobile: ''
    })

    const handleGetSystemConf = async () => {
        const {code, data, message} = await getSystemConf()
        if (code === 1) {
            Object.assign(state, data)
        }
    }

    return {
        ...toRefs(state),
        handleGetSystemConf
    }
},{
    // persist: true,
    persist: {
        storage: {
            getItem(key) {
                // @ts-ignore
                return uni.getStorageSync(key)
            },
            setItem(key, val) {
                // @ts-ignore
                uni.setStorageSync(key, val)
            }
        }
    }
})
